package com.cofey.config.server;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.config.environment.Environment;
import org.springframework.cloud.config.environment.PropertySource;
import org.springframework.stereotype.Component;

import java.util.HashMap;


/**
 * Created by cofey on 16/6/24.
 */
@Deprecated
@Component
@Aspect
public class CustomPropertyAdvice {
    private final static Logger logger = LoggerFactory.getLogger(CustomPropertyAdvice.class);

    @Pointcut("execution(public * org.springframework.cloud.config.server.environment.EnvironmentRepository.findOne(..))")
    public void init() {
    }

    @Around(value = "init()")
    public Object around(ProceedingJoinPoint pjp) throws Throwable {
        logger.info("=====>>" + pjp.getSignature().getName() + "," + pjp.getTarget().getClass());
        Environment proceed = (Environment) pjp.proceed();
        HashMap<String, Object> map = new HashMap<>();
        map.put("test.env", "test");
        PropertySource propertySource = new PropertySource("springCloudClientHostInfo", map);
        proceed.add(propertySource);
        logger.info("----->>{}", proceed);
        return proceed;
    }
}
